package com.fanketly.musicdiary.ui.screen

import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material.Scaffold
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.fanketly.musicdiary.domain.MusicUiState
import com.fanketly.musicdiary.domain.MusicViewModel
import com.fanketly.musicdiary.ui.components.MusicContentBottom
import com.fanketly.musicdiary.ui.components.MusicList
import com.fanketly.musicdiary.ui.theme.BlackBackgroundColor
import com.fanketly.musicdiary.ui.theme.TextDeepBlack

@OptIn(ExperimentalLifecycleComposeApi::class)
@Composable
fun MusicScaffold(musicViewModel: MusicViewModel = hiltViewModel()) {
    val uiState by musicViewModel.uiState.collectAsStateWithLifecycle()
    if (uiState is MusicUiState.UnKnown) return
//    val musicList = musicViewModel.getMusicListFromMusicScreen()
    Scaffold(
        backgroundColor = BlackBackgroundColor,
        bottomBar = {
            MusicContentBottom(musicViewModel)
        },
    ) {
        Surface(
//            Modifier.statusBarsPadding(),
            color = BlackBackgroundColor,
            contentColor = TextDeepBlack
        ) {
            MusicList(
                it.calculateBottomPadding(),
                list = (uiState as MusicUiState.Success).musicList,
                onClick = musicViewModel::playMusicByInfo
            )
        }
    }
}